package com.aaa.controller;

import com.aaa.entity.MyReturn;
import com.aaa.util.Constans;
import com.aaa.util.Enum01;
import com.aaa.util.ReturnStatusEnum;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.servlet.ModelAndView;

@ControllerAdvice
public class BaseController {
    public   MyReturn getSuccessReturn(MyReturn myReturn){
        myReturn.setCode(ReturnStatusEnum.SUCCESS.getCode());
        myReturn.setMsg(ReturnStatusEnum.SUCCESS.getMessage());
        return myReturn;
    }


    public   MyReturn getFailReturn(MyReturn myReturn){
        myReturn.setCode(ReturnStatusEnum.FAILE.getCode());
        myReturn.setMsg(ReturnStatusEnum.FAILE.getMessage());
        return myReturn;
    }
    public   MyReturn getUpLoadSuccessReturn(MyReturn myReturn){
        myReturn.setCode(ReturnStatusEnum.UPLOADSUCCESS.getCode());
        myReturn.setMsg(ReturnStatusEnum.UPLOADSUCCESS.getMessage());
        return myReturn;
    }
    public   MyReturn getUpLoadFailReturn(MyReturn myReturn){
        myReturn.setCode(ReturnStatusEnum.UPLOADSUCCESSFAILE.getCode());
        myReturn.setMsg(ReturnStatusEnum.UPLOADSUCCESSFAILE.getMessage());
        return myReturn;
    }





    //新增1
    public  MyReturn getSuccessResult(MyReturn myReturn) {
        if(null==myReturn){
            myReturn= new MyReturn();
        }
        myReturn.setCode(ReturnStatusEnum.SUCCESS.getCode());
        myReturn.setMsg(ReturnStatusEnum.SUCCESS.getMessage());
        return myReturn;
    }
    public  MyReturn getFailResult(MyReturn myReturn) {
        if(null==myReturn){
            myReturn= new MyReturn();
        }
        myReturn.setCode(ReturnStatusEnum.FAILE.getCode());
        myReturn.setMsg(ReturnStatusEnum.FAILE.getMessage());
        return myReturn;
    }
    public  MyReturn getLoginFailResult(MyReturn myReturn) {
        if(null==myReturn){
            myReturn= new MyReturn();
        }
        myReturn.setCode(ReturnStatusEnum.FAILE.getCode());
        myReturn.setMsg(Constans.ERROR_LOGIN);
        return myReturn;
    }

//    Spring 异常
    @ExceptionHandler(Exception.class)
    public ModelAndView toErrorPage(){
        ModelAndView mv=new ModelAndView();
        mv.setViewName("500");
        return mv;
    }

//    @ExceptionHandler(Exception.class)
//    @ResponseBody
//    public MyReturn returnErrorInfo(){
//        return this.getLoginFailResult(null);
//    }


}
